home *** CD-ROM | disk | FTP | other *** search
/ Interactive Media Design Review 1999 / Interactive Media Design Review 1999.iso / pc / Demos / Herois / Codigo.Cst / 00082_Script_Movimento linear < prev    next >
Text File  |  1999-03-19  |  3KB  |  102 lines

  1. property spr, listaMovimentos, tempo
  2. property anima, marca, deslocamento
  3. property listaTamanhos, h, w, oldTam
  4.  
  5. on getBehaviorDescription
  6.   return "Movimento linear"
  7. end
  8.  
  9. on getPropertyDescriptionList
  10.   set p_list = [ ¼
  11.     #listaMovimentos: [ #comment: "Lista de tuplas [x_ini,y_ini,x_fim,y_fim,tempo]",¼
  12.                       #format: #list,¼
  13.                      #default: [[ 100, 100, 600, 400, 5 ]] ],¼
  14.     #deslocamento: [ #comment: "Preambulo sem imagem",¼
  15.                       #format: #integer,¼
  16.                      #default: 0 ],¼
  17.   #listaTamanhos: [ #comment: "Lista de tamanhos (vazia se fixo)",¼
  18.                       #format: #list,¼
  19.                      #default: [] ]¼
  20.   ]
  21.   return p_list
  22. end
  23.  
  24. on beginSprite me  
  25.   set spr = the spriteNum of me
  26.   set x = the locH of sprite spr
  27.   set y = the locV of sprite spr
  28.   set oldTam = 100
  29.   set the visibility of sprite spr to false
  30.   inicializaMovimento
  31. end
  32.  
  33. on inicializaMovimento me
  34.   set anima = 0
  35.   set tempo = 0
  36.   repeat with i = 1 to count(listaMovimentos)
  37.     set tempo = tempo + getAt(getAt(listaMovimentos,i),5)
  38.   end repeat
  39.   set h = the height of sprite spr
  40.   set w = the width of sprite spr
  41. end
  42.  
  43. on idleSprite me
  44.   if tempo = 0 then return
  45.   if anima = 0 then
  46.     set anima = the timer + deslocamento
  47.   else
  48.     -- Tempo decorrido
  49.     global gMustUpdate
  50.     set tmp = the timer - anima
  51.     if tmp < 0 then return
  52.     else if the visibility of sprite spr = false then
  53.       set the visibility of sprite spr to true
  54.       set gMustUpdate to true
  55.     end if
  56.     set tmp = tmp mod tempo
  57.     
  58.     -- Encontra semi-reta do movimento 
  59.     set i = 1
  60.     set t = getAt(getAt(listaMovimentos,i),5)
  61.     repeat while tmp > t
  62.       set tmp = tmp - t
  63.       set i = i + 1
  64.       set t = getAt(getAt(listaMovimentos,i),5)
  65.     end repeat
  66.     set reta = getAt(listaMovimentos,i)
  67.     
  68.     -- Finalmente posicao do movimento
  69.     set xi = getAt(reta,1)
  70.     set yi = getAt(reta,2)
  71.     set xf = getAt(reta,3)
  72.     set yf = getAt(reta,4)
  73.     set x = (xf - xi) * tmp / t + xi
  74.     set y = (yf - yi) * tmp / t + yi
  75.     
  76.     if the locH of sprite spr <> x then
  77.       set the locH of sprite spr to x
  78.       set gMustUpdate to true
  79.     end if
  80.     
  81.     if the locV of sprite spr <> y then
  82.       set the locV of sprite spr to y
  83.       set gMustUpdate to true
  84.     end if
  85.     
  86.     if (count(listaTamanhos) > 0) then
  87.       set ti = getAt(getAt(listaTamanhos,i),1)
  88.       set tf = getAt(getAt(listaTamanhos,i),2)
  89.       set t = (tf - ti) * tmp / t + ti
  90.       if oldTam <> t then 
  91.         set the stretch of sprite spr to true
  92.         set the width of sprite spr to w * t / 100
  93.         set the height of sprite spr to h * t / 100
  94.         set oldTam to t
  95.         set gMustUpdate to true
  96.       end if
  97.     end if
  98.     
  99.   end if
  100.   
  101. end
  102.